import url from './url';
import Util from './util';
import Config from './config';
import Vue from 'vue';

class Notify {

    message(userNotification: any) {
        const data = userNotification.notification.data;
        switch (userNotification.notification.notificationName) {
            case 'App.DownloadInvalidImportUsers':
                const fileName = data.properties.fileToken + '.' + data.properties.fileName.split('.').pop();
                return {
                    title: '用户导入完成，但部分用户没有导入成功',
                    render: (h: any) => {
                        return h('span', {}, [
                            h('span', {}, '用户导入完成，但部分用户没有导入成功，'),
                            h('a', {
                                on: {
                                    click: () => {
                                        Util.downloadWithToken('/api/File/DownloadCommonFileByName?fileName=' + fileName, '没有成功导入的用户', fileName.split('.')[1]);
                                    },
                                },
                            }, '点击此处'),
                            h('span', {}, '下载没有导入成功的用户列表以查找原因。')
                        ]);
                    },
                };
            case 'App.SimpleMessage':
                return {
                    title: '',
                    render: (h: any) => {
                    },
                };
            case 'App.CommonMessage':
                return {
                    title: data.properties.title,
                    render: (h: any) => {
                        return h('span', {}, data.properties.content);
                    },
                };
            case 'App.HaveToCopy':
                const name_haveToCopy = data.properties.name;
                const flowInstanceName_haveToCopy = data.properties.flowInstanceName;
                const flowInstanceId_haveToCopy = data.properties.flowInstanceId;
                return {
                    title: '收到了 ' + name_haveToCopy + ' 抄送给您的流程',
                    render: (h: any) => {
                        return h('span', {}, [
                            h('span', {}, '收到了 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, name_haveToCopy),
                            h('span', {}, ' 抄送给您的名称为 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, flowInstanceName_haveToCopy),
                            h('span', {}, ' 的流程，请 '),
                            h('a', {
                                on: {
                                    click: () => {
                                        location.href = '/?#/flow-instance-operation/flow-instance-detail/copy/' + flowInstanceId_haveToCopy;
                                    },
                                },
                            }, '点击此处'),
                            h('span', {}, ' 查看详情。')
                        ]);
                    },
                };
            case 'App.HaveToVerify':
                const name_haveToVerify = data.properties.name;
                const flowInstanceName_haveToVerify = data.properties.flowInstanceName;
                const flowInstanceId_haveToVerify = data.properties.flowInstanceId;
                return {
                    title: name_haveToVerify + ' 已处理了您发起的流程',
                    render: (h: any) => {
                        return h('span', {}, [
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, name_haveToVerify),
                            h('span', {}, ' 已处理了您发起的名称为 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, flowInstanceName_haveToVerify),
                            h('span', {}, ' 的流程，请 '),
                            h('a', {
                                on: {
                                    click: () => {
                                        location.href = '/?#/flow-instance-operation/flow-instance-detail/launch/' + flowInstanceId_haveToVerify;
                                    },
                                },
                            }, '点击此处'),
                            h('span', {}, ' 查看详情。')
                        ]);
                    },
                };
            case 'App.NeedToVerify':
                const name_needToVerify = data.properties.name;
                const flowInstanceName_needToVerify = data.properties.flowInstanceName;
                const flowInstanceId_needToVerify = data.properties.flowInstanceId;
                return {
                    title: '收到了 ' + name_needToVerify + ' 发起的流程',
                    render: (h: any) => {
                        return h('span', {}, [
                            h('span', {}, '收到了 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, name_needToVerify),
                            h('span', {}, ' 发送给您的名称为 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, flowInstanceName_needToVerify),
                            h('span', {}, ' 的流程，请 '),
                            h('a', {
                                on: {
                                    click: () => {
                                        location.href = '/?#/flow-instance-operation/flow-instance-detail/backlog/' + flowInstanceId_needToVerify;
                                    },
                                },
                            }, '点击此处'),
                            h('span', {}, ' 查看详情并及时处理。')
                        ]);
                    },
                };
            case 'App.ConcurrentLoginPerUser':
                const name_concurrentLoginPerUser = data.properties.name;
                const remoteIpAddress_concurrentLoginPerUser = data.properties.remoteIpAddress;
                const dateTime_concurrentLoginPerUser = data.properties.dateTime;
                return {
                    title: '用户 ' + name_concurrentLoginPerUser + ' 在多台机器同时登录',
                    render: (h: any) => {
                        return h('span', {}, [
                            h('span', {}, '用户 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, name_concurrentLoginPerUser),
                            h('span', {}, ' 于 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, dateTime_concurrentLoginPerUser),
                            h('span', {}, ' 在IP地址为 '),
                            h('span', {
                                style: {
                                    fontWeight: 'bolder',
                                },
                            }, remoteIpAddress_concurrentLoginPerUser),
                            h('span', {}, ' 的机器上再次登录，当前机器被迫退出。')
                        ]);
                    },
                };
        }
    }

    print(componentId: string, render: any) {
        const Component = Vue.extend(
            Vue.component(componentId, {
                render: render,
            })
        );
        let vm = new Component({});
        vm.$mount();
        const html = vm.$el.outerHTML;
        vm.$destroy();
        return html;
    }
}

export default new Notify();
